

//手机登录验证
$(function () {
    $(".logmain>form").validate({
        rules: {
            phone: {
                required: true,
            },
            upwd: {
                required: true,
            }
        },
        messages: {
            phone: {
                required: "请输入手机",
            },
            upwd: {
                required: "请输入密码",
            }
        },
        submitHandler() {
            $.ajax({
                url: "./account/login",
                type: "post",
                data: $("form").serialize()//前端发送到服务器的数据 data
            }).then(function (response) { //服务器响应到前端的数据 response

                if (response.status == 200) {
                    layer.msg("登录成功")
                    

                    localStorage.setItem("userinfo",JSON.stringify(response.data))




                    setTimeout(function () {
                        location = "index.html";
                    }, 1000)
                } else {
                    layer.msg("登录失败,用户名或密码错误!");
                }
            })
            return false;
        }
    })
})


//注册验证
$(function () {
    $(".register>form").validate({
        rules: {
            phone: {
                required: true,
                digits: true,
                rangelength: [11, 11]
            },
            nickname: {
                required: true,
            },
            upwd: {
                required: true,
                rangelength: [6, 18]
            },
            upwd2: {
                equalTo: "#upwd"
            },
            agree: {
                required: true
            }

        },
        messages: {
            phone: {
                required: "手机必填",
                digits: "只能是数字",
                rangelength: "手机号不合法"
            },
            nickname: {
                required: "昵称必填"
            },
            upwd: {
                required: "密码必填",
                rangelength: "密码必须是{0}-{1}位"
            },
            upwd2: {
                equalTo: "2次密码不相同"
            },
            agree: {
                required: "请同意相关条款"
            }
        },
        submitHandler() {
            $.ajax({
                url: "./account/reg",
                type: "post",
                data: $("form").serialize()//前端发送到服务器的数据 data
            }).then(function (response) { //服务器响应到前端的数据 response

                //    layer.open()
                // layer.msg()
                layer.msg("注册成功")

                if (response.status == 200) {
                    layer.msg("注册成功");
                    location = "index.html";
                } else {
                    layer.msg("注册失败")
                }
            })
            return false;
        }
    })

})

